package com.industry.examinaion.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.industry.examinaion.dal.dataobject.ExaminaionPaper;
import com.industry.examinaion.dal.dataobject.ExaminaionPaperAnswer;
import com.industry.examinaion.dal.dataobject.ExaminaionPaperQuestion;
import com.industry.examinaion.dal.dataobject.ExaminaionQuestion;
import com.industry.examinaion.dal.db.ExaminaionPaperQuestionMapper;
import com.industry.examinaion.dal.db.ExaminaionQuestionMapper;
import com.industry.framework.core.generic.AbstractCoreGenericController;
import com.industry.framework.core.generic.AbstractCoreGenericService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ExaminaionPaperAnswerService extends AbstractCoreGenericService<ExaminaionPaperAnswer,String> {

    private final static String splitor = "###";


    @Resource
    ExaminaionQuestionMapper questionMapper;


    //根据交卷内容 +  问题内容 生成答案结果
    public void createExaminaionPaper(ExaminaionPaper examinaionPaper
            , List<ExaminaionPaperQuestion> examinaionPaperQuestions , Map<String,String> examinaionPaperAnswerMap) {
        if(!CollectionUtils.isEmpty(examinaionPaperQuestions) && !CollectionUtils.isEmpty(examinaionPaperAnswerMap)){
            //查询试题 对应的 题目数据
            List<String> examQuestionIds = examinaionPaperQuestions.stream().map(ExaminaionPaperQuestion::getExaminaionQuestionId).collect(Collectors.toList());
            List<ExaminaionQuestion> quesionTemples = questionMapper.selectByIds(examQuestionIds);
            for (ExaminaionQuestion examinaionPaperQuestion : quesionTemples) {
                String answerTemple = examinaionPaperQuestion.getAnswer();
//                submitCheck();
                }

            }
        }

    /**
     * 核对
     * @param questionType 问题类型
     * @param answerTemple 问题答案
     * @param answer 试卷问题答案
     * @return
     */
    public boolean submitCheck(String questionType , String answerTemple , String answer){
        return true;
//        switch (questionType){
//            //单选
//            case "1":
//                return StringUtils.equals(answerTemple, answer);
//            //多选
//            case "2":
//                return StringUtils.equals(answer, answerTemple);
//            //填空
//            case "3":
//                return StringUtils.equals(answer, answerTemple);
//            //简答
//            case "4":
//
//        }
    }
}
